<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>社交网站 - 导航栏示例</title>
    <!-- 引入Bootstrap 5 -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- 引入Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <style>
        :root {
            --primary: #1877F2;
            --primary-light: #E8F3FF;
            --secondary: #65676B;
            --light-bg: #F0F2F5;
            --card-bg: #FFFFFF;
            --border-color: #DADDE1;
            --text-dark: #1C1E21;
            --text-light: #65676B;
            --radius: 8px;
            --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }
        
        body {
            font-family: 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            color: var(--text-dark);
            line-height: 1.5;
            padding-top: 56px; /* 为固定导航栏留出空间 */
        }
        
        /* 导航栏样式 */
        .navbar {
            background-color: white;
            border-bottom: 1px solid var(--border-color);
            box-shadow: var(--shadow);
            padding: 0.5rem 1rem;
        }
        
        /* Logo样式 */
        .navbar-brand {
            font-weight: 700;
            color: var(--primary);
            font-size: 1.5rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        
        .navbar-brand i {
            font-size: 1.8rem;
        }
        
        /* 主导航样式 */
        .main-nav .nav-link {
            color: var(--text-dark);
            font-weight: 500;
            padding: 0.5rem 1rem;
            margin: 0 0.25rem;
            border-radius: var(--radius);
            transition: all 0.2s;
        }
        
        .main-nav .nav-link:hover,
        .main-nav .nav-link.active {
            color: var(--primary);
            background-color: var(--primary-light);
        }
        
        /* 搜索框样式 */
        .search-container {
            position: relative;
            max-width: 400px;
            width: 100%;
        }
        
        .search-input {
            width: 100%;
            padding: 0.5rem 1rem 0.5rem 2.5rem;
            border-radius: 20px;
            border: 1px solid var(--border-color);
            background-color: var(--light-bg);
            transition: all 0.2s;
        }
        
        .search-input:focus {
            outline: none;
            border-color: var(--primary);
            background-color: white;
            box-shadow: 0 0 0 2px var(--primary-light);
        }
        
        .search-icon {
            position: absolute;
            left: 0.75rem;
            top: 50%;
            transform: translateY(-50%);
            color: var(--secondary);
        }
        
        /* 搜索联想下拉框 */
        .search-suggestions {
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
            background-color: white;
            border-radius: 0 0 var(--radius) var(--radius);
            box-shadow: var(--shadow);
            z-index: 1000;
            margin-top: 2px;
            max-height: 0;
            overflow: hidden;
            transition: max-height 0.3s ease-out;
        }
        
        .search-suggestions.active {
            max-height: 300px;
            border: 1px solid var(--border-color);
            border-top: none;
        }
        
        .suggestion-item {
            padding: 0.75rem 1rem;
            cursor: pointer;
            transition: background-color 0.2s;
        }
        
        .suggestion-item:hover {
            background-color: var(--light-bg);
        }
        
        .suggestion-item .highlight {
            color: var(--primary);
            font-weight: 600;
        }
        
        /* 用户区域样式 */
        .user-area {
            display: flex;
            align-items: center;
            gap: 1rem;
        }
        
        .auth-buttons {
            display: flex;
            gap: 0.5rem;
        }
        
        .auth-buttons .btn {
            padding: 0.4rem 1rem;
            border-radius: 20px;
            font-weight: 500;
        }
        
        .user-menu {
            position: relative;
        }
        
        .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            object-fit: cover;
            cursor: pointer;
            border: 2px solid transparent;
            transition: border-color 0.2s;
        }
        
        .user-avatar:hover {
            border-color: var(--primary);
        }
        
        /* 下拉菜单 */
        .dropdown-menu {
            position: absolute;
            right: 0;
            top: 100%;
            margin-top: 0.5rem;
            min-width: 200px;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            border: 1px solid var(--border-color);
            padding: 0.5rem 0;
            background-color: white;
            z-index: 1000;
            display: none;
        }
        
        .dropdown-menu.active {
            display: block;
        }
        
        .dropdown-item {
            padding: 0.75rem 1.5rem;
            color: var(--text-dark);
            display: flex;
            align-items: center;
            gap: 0.75rem;
            transition: background-color 0.2s;
        }
        
        .dropdown-item:hover {
            background-color: var(--light-bg);
            color: var(--primary);
        }
        
        .dropdown-divider {
            height: 1px;
            background-color: var(--border-color);
            margin: 0.5rem 0;
        }
        
        /* 汉堡菜单按钮 */
        .hamburger-btn {
            display: none;
            background: none;
            border: none;
            color: var(--text-dark);
            font-size: 1.5rem;
            cursor: pointer;
        }
        
        /* 移动端侧边菜单 */
        .mobile-menu {
            position: fixed;
            top: 0;
            left: -300px;
            width: 280px;
            height: 100vh;
            background-color: white;
            box-shadow: var(--shadow);
            z-index: 2000;
            transition: left 0.3s ease;
            padding-top: 70px;
            padding-left: 1rem;
        }
        
        .mobile-menu.active {
            left: 0;
        }
        
        .mobile-menu .nav-link {
            display: block;
            padding: 0.75rem 1rem;
            color: var(--text-dark);
            font-weight: 500;
            border-radius: var(--radius);
            margin-bottom: 0.25rem;
        }
        
        .mobile-menu .nav-link:hover,
        .mobile-menu .nav-link.active {
            color: var(--primary);
            background-color: var(--primary-light);
        }
        
        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-color: rgba(0, 0, 0, 0.5);
            z-index: 1500;
            display: none;
        }
        
        .overlay.active {
            display: block;
        }
        
        /* 响应式调整 */
        @media (max-width: 992px) {
            .main-nav {
                display: none;
            }
            
            .hamburger-btn {
                display: block;
            }
            
            .search-container {
                max-width: 250px;
            }
        }
        
        @media (max-width: 576px) {
            .search-container {
                display: none;
            }
            
            .mobile-search {
                padding: 0.75rem 1rem;
                border-bottom: 1px solid var(--border-color);
            }
            
            .mobile-search .search-container {
                display: block;
                max-width: 100%;
            }
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar fixed-top">
        <div class="container-fluid">
            <!-- 左侧：Logo + 汉堡菜单按钮 -->
            <div class="d-flex align-items-center gap-3">
                <button class="hamburger-btn" id="hamburgerBtn">
                    <i class="fas fa-bars"></i>
                </button>
                <a class="navbar-brand" href="#">
                    <i class="fab fa-facebook-square"></i>
                    <span>社交圈</span>
                </a>
            </div>
            
            <!-- 主导航 - 桌面端显示 -->
            <ul class="nav main-nav">
                <li class="nav-item">
                    <a class="nav-link active" href="#"><i class="fas fa-home me-1"></i>首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#"><i class="fas fa-newspaper me-1"></i>文章</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#"><i class="fas fa-question-circle me-1"></i>问答</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#"><i class="fas fa-calendar-alt me-1"></i>活动</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#"><i class="fas fa-shopping-bag me-1"></i>商品</a>
                </li>
            </ul>
            
            <!-- 中间：搜索框 -->
            <div class="search-container">
                <i class="fas fa-search search-icon"></i>
                <input type="text" class="search-input" placeholder="搜索内容、用户或话题..." id="searchInput">
                
                <!-- 搜索联想下拉框 -->
                <div class="search-suggestions" id="searchSuggestions">
                    <div class="suggestion-item">
                        <i class="fas fa-user text-secondary me-2"></i>
                        <span>用户：<span class="highlight">张明</span></span>
                    </div>
                    <div class="suggestion-item">
                        <i class="fas fa-newspaper text-secondary me-2"></i>
                        <span>文章：如何提高<span class="highlight">社交</span>能力</span>
                    </div>
                    <div class="suggestion-item">
                        <i class="fas fa-hashtag text-secondary me-2"></i>
                        <span>话题：#<span class="highlight">科技</span>新闻#</span>
                    </div>
                    <div class="suggestion-item">
                        <i class="fas fa-question-circle text-secondary me-2"></i>
                        <span>问答：有哪些好用的<span class="highlight">社交</span>技巧？</span>
                    </div>
                    <div class="suggestion-item">
                        <i class="fas fa-calendar-alt text-secondary me-2"></i>
                        <span>活动：2023<span class="highlight">社交</span>网络峰会</span>
                    </div>
                </div>
            </div>
            
            <!-- 右侧：用户入口 -->
            <div class="user-area">
                <!-- 已登录状态：头像下拉菜单 -->
                <div class="user-menu" id="userMenu">
                    <img src="https://picsum.photos/id/64/100/100" alt="用户头像" class="user-avatar" id="userAvatar">
                    
                    <!-- 下拉菜单 -->
                    <div class="dropdown-menu" id="dropdownMenu">
                        <a class="dropdown-item" href="#">
                            <i class="fas fa-user-circle"></i>
                            <span>个人中心</span>
                        </a>
                        <a class="dropdown-item" href="#">
                            <i class="fas fa-bell"></i>
                            <span>消息通知</span>
                            <span class="badge bg-primary ms-auto">3</span>
                        </a>
                        <a class="dropdown-item" href="#">
                            <i class="fas fa-cog"></i>
                            <span>设置</span>
                        </a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="#">
                            <i class="fas fa-sign-out-alt"></i>
                            <span>退出登录</span>
                        </a>
                    </div>
                </div>
                
                <!-- 未登录状态：登录/注册按钮 (默认隐藏，需要时显示) -->
                <!-- <div class="auth-buttons">
                    <button class="btn btn-outline-primary">登录</button>
                    <button class="btn btn-primary">注册</button>
                </div> -->
            </div>
        </div>
    </nav>
    
    <!-- 移动端侧边菜单 -->
    <div class="mobile-menu" id="mobileMenu">
        <div class="mobile-search">
            <div class="search-container">
                <i class="fas fa-search search-icon"></i>
                <input type="text" class="search-input" placeholder="搜索内容、用户或话题...">
            </div>
        </div>
        <a class="nav-link active" href="#"><i class="fas fa-home me-2"></i>首页</a>
        <a class="nav-link" href="#"><i class="fas fa-newspaper me-2"></i>文章</a>
        <a class="nav-link" href="#"><i class="fas fa-question-circle me-2"></i>问答</a>
        <a class="nav-link" href="#"><i class="fas fa-calendar-alt me-2"></i>活动</a>
        <a class="nav-link" href="#"><i class="fas fa-shopping-bag me-2"></i>商品</a>
        <div class="dropdown-divider mt-3 mb-3"></div>
        <a class="nav-link" href="#"><i class="fas fa-user-circle me-2"></i>个人中心</a>
        <a class="nav-link" href="#"><i class="fas fa-bell me-2"></i>消息通知 <span class="badge bg-primary">3</span></a>
        <a class="nav-link" href="#"><i class="fas fa-cog me-2"></i>设置</a>
        <a class="nav-link" href="#"><i class="fas fa-sign-out-alt me-2"></i>退出登录</a>
    </div>
    
    <!-- 遮罩层 -->
    <div class="overlay" id="overlay"></div>
    
    <!-- 引入Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // 获取DOM元素
            const hamburgerBtn = document.getElementById('hamburgerBtn');
            const mobileMenu = document.getElementById('mobileMenu');
            const overlay = document.getElementById('overlay');
            const userAvatar = document.getElementById('userAvatar');
            const dropdownMenu = document.getElementById('dropdownMenu');
            const searchInput = document.getElementById('searchInput');
            const searchSuggestions = document.getElementById('searchSuggestions');
            
            // 移动端菜单控制
            hamburgerBtn.addEventListener('click', function() {
                mobileMenu.classList.toggle('active');
                overlay.classList.toggle('active');
                // 切换图标
                const icon = this.querySelector('i');
                if (icon.classList.contains('fa-bars')) {
                    icon.classList.remove('fa-bars');
                    icon.classList.add('fa-times');
                } else {
                    icon.classList.remove('fa-times');
                    icon.classList.add('fa-bars');
                }
            });
            
            // 点击遮罩层关闭移动端菜单
            overlay.addEventListener('click', function() {
                mobileMenu.classList.remove('active');
                overlay.classList.remove('active');
                // 恢复图标
                const icon = hamburgerBtn.querySelector('i');
                if (icon.classList.contains('fa-times')) {
                    icon.classList.remove('fa-times');
                    icon.classList.add('fa-bars');
                }
            });
            
            // 用户下拉菜单控制
            userAvatar.addEventListener('click', function(e) {
                e.stopPropagation(); // 阻止事件冒泡
                dropdownMenu.classList.toggle('active');
            });
            
            // 点击页面其他地方关闭下拉菜单
            document.addEventListener('click', function() {
                dropdownMenu.classList.remove('active');
            });
            
            // 搜索联想功能
            searchInput.addEventListener('focus', function() {
                searchSuggestions.classList.add('active');
            });
            
            searchInput.addEventListener('blur', function() {
                // 延迟关闭，以便点击联想项
                setTimeout(() => {
                    searchSuggestions.classList.remove('active');
                }, 200);
            });
            
            // 点击联想项填充搜索框
            const suggestionItems = document.querySelectorAll('.suggestion-item');
            suggestionItems.forEach(item => {
                item.addEventListener('click', function() {
                    // 提取并格式化搜索文本
                    const text = this.textContent.trim();
                    searchInput.value = text.replace(/^[^：]+：/, ''); // 移除前缀（如"用户："）
                    searchSuggestions.classList.remove('active');
                });
            });
            
            // 搜索输入处理（实际项目中可根据输入实时更新联想列表）
            searchInput.addEventListener('input', function() {
                const value = this.value.toLowerCase();
                if (value.length > 0) {
                    searchSuggestions.classList.add('active');
                    // 这里可以根据输入值动态更新联想列表
                } else {
                    searchSuggestions.classList.remove('active');
                }
            });
            
            // 点击ESC关闭所有弹出层
            document.addEventListener('keydown', function(e) {
                if (e.key === 'Escape') {
                    dropdownMenu.classList.remove('active');
                    searchSuggestions.classList.remove('active');
                    mobileMenu.classList.remove('active');
                    overlay.classList.remove('active');
                    // 恢复汉堡菜单图标
                    const icon = hamburgerBtn.querySelector('i');
                    if (icon.classList.contains('fa-times')) {
                        icon.classList.remove('fa-times');
                        icon.classList.add('fa-bars');
                    }
                }
            });
        });
    </script>
</body>
</html>
    